package cn.jzx.scalademo1

class Student(n: String, a: Int) {
  private var name = n //私有变量，伴生对象可以访问
  private var age = a
}

//伴生对象
object Student {
  def apply(n: String, a: Int): Student = new Student(n, a)

  def main(args: Array[String]): Unit = {
    val stu = Student("Jason", 9) //通过伴生对象的apply()方法创建实例
    println(stu.name)
  }
}